package com.wsx.ones.cloud.hello;

import com.wsx.ones.cloud.product.Product;
import com.wsx.ones.cloud.service.ClientService;
import com.wsx.ones.cloud.service.HelloService;
import com.wsx.ones.cloud.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangshuaixin on 17/5/7.
 */
@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    private ClientService clientService;

    @Autowired
    private HelloService helloService;

    @Autowired
    private ProductService productService;

    /**
     * 该功能是基于客户端的直连url进行的远程服务调用
     * @return
     */
    @RequestMapping(
            value = "/get/test",
            method = {RequestMethod.GET}
    )
    public String hello() {
        //需要指定注册服务的name
        return helloService.getWords("eureka-client");
    }

    /**
     * 该功能是基于feign的接口设计，实现远程服务调用
     * @return
     */
    @RequestMapping(
            value = "/get/remote",
            method = {RequestMethod.GET}
    )
    public String remote() {
        return clientService.getValue();
    }

    @RequestMapping(
            value = "/save/product",
            method = {RequestMethod.POST}
    )
    public String remotePost(Product product) {
        String rtn = productService.getPost(product);
        return rtn;
    }


}
